const express=require('express');
const route=require('./route/index');
const cors=require('cors');
const {server}=require('./config');
const {getIp,sendErr}=require('./utils/index');
const token=require('./utils/token')
const app=express();
app.use(express.json())
app.use('/',express.static(__dirname+'/dist'))
app.use(cors())
//应用token
token(app);
//应用路由
route(app);

//日志
app.use((err,req,res,next)=>{
    if(err){
        console.log(`${new Date()}:${err.message}`);
        sendErr(res,err.message);
        return;
    }
})
//开始监听
app.listen(server.port,(err)=>{
    if(err){
        console.error(err.message,err);
    }else{
        console.log(`${new Date()}:http://${getIp()}:${server.port}`)
    }
})


